home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CICA 1995 August
/
CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso
/
disc2
/
demo
/
pwrtcp11.exe
/
FTPC.C_
/
FTPC.bin
Wrap
Text File
|
1995-02-17
|
50KB
|
1,763 lines
#pragma warning(disable:4001)
//***************************************************************************
//
// Module: ftptest.c
//
// Tab setting: 4
//
//***************************************************************************
//
// Written by Dart Communication Application Programming Group.
// Copyright (c) 1994 Dart Communications. All Rights Reserved.
//
// Purpose: Provides access to functions in FTP interface
// DLL via dialog box.
//
// Author: Roger Lathrop
//
// History: 11/94 - First version.
//
//***************************************************************************
#include <malloc.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
// FTP Include files. Common brings in windows.h for us.
#include "..\..\include\common.h"
#include "..\..\include\powertcp.h"
//#include "powerftp.h"
// Our resource file header.
#include "ftprc.h"
/****************************************************************************
* Static variables for module.
****************************************************************************/
static HICON hOurIcon; // Handle to our application icon.
static HPOWERTCP hFtp; // Handle to PowerFTP session.
static BOOL ClosePending; // Close app when logout complete.
static HFILE hSendFile = HFILE_ERROR; // File handle for sending data.
static HFILE hRecvFile = HFILE_ERROR; // File handle for receiving data.
static DWORD BytesSent; // Accumulated bytes sent per transfer.
static DWORD BytesReceived; // Accumulated bytes received per transfer.
static CONNECTEVENT lpfnConnectEvent;
static LOGEVENT lpfnLogEvent;
static RECVEVENT lpfnRecvEvent;
static REPLYEVENT lpfnReplyEvent;
static SENDEVENT lpfnSendEvent;
// A single, static buffer is allocate here for sending data.
#define SEND_BUFFER_SIZE 4096
static char SendBuffer[SEND_BUFFER_SIZE];
/****************************************************************************
* Routines for fetching parameters from edit controls.
****************************************************************************/
//---------------------------------------------------------------------------
// Name.......: GetStringParam
// Purpose....: Get a string from an edit control.
//
// Parameters.: hWnd - HWND Main window handle.
// CtlId - WORD Control id of edit control
// Required - BOOL Parameter is required.
//
// Returns....: Malloced pointer to string, or NULL if malloc fails
//---------------------------------------------------------------------------
static char * GetStringParam(HWND hWnd,WORD CtlId,BOOL Required)
{ char *p;
WORD len;
// Get length of string in edit control. If length is 0,
// and the parameter is required, then ding the speaker,
// set focus to control, and put message in status bar.
len = (WORD)SendDlgItemMessage(hWnd,CtlId,WM_GETTEXTLENGTH,0,0);
if(len == 0 && Required)
{
MessageBeep(0);
SetFocus(GetDlgItem(hWnd,CtlId));
SetDlgItemText(hWnd,STC_STATUS,"Parameter required.");
return NULL;
}
// Allocate space for string and a NULL byte.
len++;
p = malloc(len);
// Malloc should never fail, unless we have a memory leak,
// but best to check anyway.
if(p)
{ // Extract string from edit control.
SendDlgItemMessage(hWnd,CtlId,WM_GETTEXT,len,(LPARAM)(LPSTR)p);
}
return p;
}
//---------------------------------------------------------------------------
// Name.......: FreeStringParam
// Purpose....: _ffree a string allocated by GetStringParam.
// Checks for NULL string so caller doesn't have to.
//
// Parameters.: s - Char * String from GetStringParam
//
// Returns....: void
//---------------------------------------------------------------------------
static void FreeStringParam(char *s)
{
if(s)
{
free(s);
}
}
//---------------------------------------------------------------------------
// Name.......: GetLongParam
// Purpose....: Get a long int from an edit control.
//
// Parameters.: hWnd - HWND Main window handle.
// CtlId - WORD Control id of edit control
// pval - LPDWORD far pointer to area to receive value.
//
// Returns....: True if numeric value in edit control.
//---------------------------------------------------------------------------
BOOL GetLongParam(HWND hWnd,WORD CtlId,LPDWORD pval)
{ char *p;
char *psave;
// Get text from edit control. Skip leading whitespace, then
// if first character is a digit, convert string to long.
// If not a digit, ding the speaker and set focus to control.
p = GetStringParam(hWnd,CtlId,TRUE);
psave = p;
if(p)
{
while(isspace(*p))
{
p++;
}
if(isdigit(*p))
{
*pval = atol(p);
free(psave);
return TRUE;
}
else
{
MessageBeep(0);
SetFocus(GetDlgItem(hWnd,CtlId));
SetDlgItemText(hWnd,STC_STATUS,"Numeric value required.");
free(psave);
return FALSE;
}
}
return FALSE;
}
//---------------------------------------------------------------------------
// Name.......: ShowResult
// Purpose....: Print Success or Failed in status line
//
// Parameters.: hWnd - Our window handle.
// Success - BOOL True for success
//
// Returns....: void
//---------------------------------------------------------------------------
static void ShowResult(HWND hWnd,BOOL Success)
{
// Diagnose the obvios case for a failure...
if(!Success && hFtp == NULL)
{
SetDlgItemText(hWnd,STC_STATUS,"Failed - Not Logged on.");
}
else
{
SetDlgItemText(hWnd,STC_STATUS,Success ? "Success" : "Failed");
}
}
/****************************************************************************
* Routines to kick off or abort a send or receive request.
****************************************************************************/
//---------------------------------------------------------------------------
// Name.......: AbortSend
// Purpose....: If sending from file, close it.
//
// Parameters.: void
//
// Returns....: void
//---------------------------------------------------------------------------
static void AbortSend(void)
{
if(hSendFile != HFILE_ERROR)
{
_lclose(hSendFile);
hSendFile = HFILE_ERROR;
}
}
//---------------------------------------------------------------------------
// Name.......: AbortRecv
// Purpose....: If receiving into file, close it.
//
// Parameters.: void
//
// Returns....: void
//---------------------------------------------------------------------------
static void AbortRecv(void)
{
if(hRecvFile != HFILE_ERROR)
{
_lclose(hRecvFile);
hRecvFile = HFILE_ERROR;
}
}
//---------------------------------------------------------------------------
// Name.......: StartSend
// Purpose....: Prepare to send a file, if it is safe to do so.
//
// Parameters.: hWnd - Our window handle.
// LocalName - LPSTR of local file name to send.
//
// Returns....: True if ok to send.
//---------------------------------------------------------------------------
static BOOL StartSend(HWND hWnd,LPSTR LocalName)
{ int res;
OFSTRUCT ofsFile;
// If we are already sending a file, then hSendFile will be
// valid. In this case, ask the user what to do.
// Abort? - Close file, send AbortFtp, and start new send.
// Retry? - See if previous transfer has completed yet.
// Ignore? - Cancel request to send.
while(hSendFile != HFILE_ERROR)
{
res = MessageBox(hWnd,
"A transfer is already in progress.\n"
"Abort aborts active transfer.\n"
"Retry proceeds if transfer has completed.\n"
"Ignore cancels your request.\n",
"FTPTest",
MB_ICONSTOP | MB_ABORTRETRYIGNORE);
switch(res)
{
case IDABORT: AbortSend();
AbortFtp(hFtp);
break;
case IDRETRY: continue;
case IDIGNORE: return FALSE;
}
}
// Ok to attempt send. See if we can open the file.
ofsFile.cBytes = sizeof ofsFile;
hSendFile = OpenFile(LocalName,&ofsFile,OF_READ | OF_SHARE_COMPAT);
if(hSendFile == HFILE_ERROR)
{
MessageBox(hWnd,"Unable to open file","FTPTest",MB_ICONSTOP | MB_OK);
return FALSE;
}
// Reset stats for transfer
BytesSent = 0;
return TRUE;
}
//---------------------------------------------------------------------------
// Name.......: StartReceive
// Purpose....: Prepare to receive a file.
//
// Parameters.: hWnd - Our window handle.
// LocalName - LPSTR of local file to receive into.
// If NULL, then receive into edit window.
//
// Returns....: True if ok to send.
//---------------------------------------------------------------------------
static BOOL StartReceive(HWND hWnd,char *LocalName)
{ int res;
OFSTRUCT ofsFile;
// If LocalName is provided, then we receive into a file,
// otherwise we receive into the edit box.
if(LocalName)
{
// If we are already receiving a file, then hRecvFile will be
// valid. In this case, ask the user what to do.
// Abort? - Close file, send AbortFtp, and start new recv.
// Retry? - See if previous transfer has completed yet.
// Ignore? - Cancel request to receive.
while(hRecvFile != HFILE_ERROR)
{
res = MessageBox(hWnd,
"A transfer is already in progress.\n"
"Abort aborts active transfer.\n"
"Retry proceeds if transfer has completed.\n"
"Ignore cancels your request.\n",
"FTPTest",
MB_ICONSTOP | MB_ABORTRETRYIGNORE);
switch(res)
{
case IDABORT: AbortRecv();
AbortFtp(hFtp);
break;
case IDRETRY: continue;
case IDIGNORE: return FALSE;
}
}
// Ok to receive, see if we can open the file to receive into.
// NB: This action truncates the file if it exists without warning!
ofsFile.cBytes = sizeof ofsFile;
hRecvFile = OpenFile(LocalName,
&ofsFile,
OF_WRITE | OF_CREATE);
if(hRecvFile == HFILE_ERROR)
{
MessageBox(hWnd,"Unable to open file","FTPTest",MB_ICONSTOP | MB_OK);
return FALSE;
}
}
else
{
// We are going to receive into the edit control. Clear it first.
SendDlgItemMessage(hWnd,
EDC_RECEIVE,
WM_SETTEXT,
0,
(LPARAM)(LPSTR)"");
}
// Reset stats for transfer
BytesReceived = 0;
return TRUE;
}
/****************************************************************************
* CALLBACK FUNCTIONS. Called asynchronously by DLL as events occur.
****************************************************************************/
//---------------------------------------------------------------------------
// Name.......: ConnectEvent
// Purpose....: Callback function for connect event notification
//
// Parameters.: hSession - HPOWERTCP Session id.
// UserData - DWORD User data supplied to loginhost.
// RemoteDotAddr - LPCSTR Remote dot address
// RemotePort - WORD Remote port id.
// LocalDotAddr - LPCSTR Local dot address
// LocalPort - WORD Local port id.
// LocalName - LPCSTR Local name.
//
// Returns....: void
//---------------------------------------------------------------------------
void CALLBACK ConnectEvent(HPOWERTCP hSession,
DWORD UserData,
LPCSTR RemoteDotAddr,
WORD RemotePort,
LPCSTR LocalDotAddr,
WORD LocalPort,
LPCSTR LocalName)
{ int len;
static char msg[] = "Connected to:";
char *txt;
// This callback is invoked when we connect end-to-end. Put
// the connected to dot address in status box.
len = RemoteDotAddr ? _fstrlen(RemoteDotAddr) : 0;
len += sizeof(msg)+1;
txt = malloc(len);
if(!txt)
{
return;
}
strcpy(txt,msg);
if(RemoteDotAddr)
{
_fstrcat(txt,RemoteDotAddr);
}
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,txt);
free(txt);
}
//---------------------------------------------------------------------------
// Name.......: LogEvent
// Purpose....: Callback function for log event notification
//
// Parameters.: hSession - HPOWERTCP Session id.
// UserData - DWORD User data supplied to loginhost.
// Message - LPCSTR to log event message
//
// Returns....: void
//---------------------------------------------------------------------------
void CALLBACK LogEvent(HPOWERTCP hSession,
DWORD UserData,
LPCSTR Message)
{
// Just plop the string in the Log list box control.
SendDlgItemMessage((HWND)(WORD)UserData,LBC_LOG,LB_ADDSTRING
,0,(LPARAM)Message);
}
//---------------------------------------------------------------------------
// Name.......: RecvEvent
// Purpose....: Callback function for received data notification
//
// Parameters.: Data - LPVOID pointer to data
// ByteCnt - size_t number of bytes in Data
//
// Returns....: void
//---------------------------------------------------------------------------
void CALLBACK RecvEvent(HPOWERTCP hSession,
DWORD UserData,
LPVOID Data,
size_t ByteCnt)
{ LPSTR p;
char Status[64];
UINT Written;
// This callback function is invoked when data arrives for us
// from remote station, or to indicate the data connection
// has been closed. Check ByteCnt to determine which case this is.
if(ByteCnt)
{
BytesReceived += ByteCnt;
// We may be receiving data into edit control or file. If hRecvFile
// file handle is valid, then write data to file.
if(hRecvFile != HFILE_ERROR)
{
Written = _lwrite(hRecvFile,Data,ByteCnt);
if(Written != ByteCnt)
{
wsprintf(Status,"%ld bytes received. Error Writing File.",
BytesReceived);
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,Status);
return;
}
else
{
// Update status line to reflect DONE.
wsprintf(Status,"%ld bytes received.",
BytesReceived);
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,Status);
}
}
else
{
// Write data to edit control. Data WILL NOT contain
// a terminating NULL, so duplicate the data, add
// a NULL byte, then write to edit control. If the
// alloc fails, we silently drop the data.
//MJB p = _fmalloc(ByteCnt+1);
p = (LPSTR)malloc(ByteCnt+1);
if(p)
{
_fmemcpy(p,Data,ByteCnt);
p[ByteCnt] = '\0';
SendDlgItemMessage((HWND)(WORD)UserData,
EDC_RECEIVE,
EM_SETSEL,
TRUE,
MAKELPARAM(-1,-1));
SendDlgItemMessage((HWND)(WORD)UserData,
EDC_RECEIVE,
EM_REPLACESEL,
0,
(LPARAM)p);
// MJB _ffree(p);
free((char *)p);
}
}
}
else
{
// Data transfer complete. If receiving into file, close
// the file now. Reset hRecvFile handle.
if(hRecvFile != HFILE_ERROR)
{
_lclose(hRecvFile);
hRecvFile = HFILE_ERROR;
// Update status line to reflect DONE.
wsprintf(Status,"%ld bytes received. DONE.",
BytesReceived);
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,Status);
}
BytesReceived = 0;
}
}
//---------------------------------------------------------------------------
// Name.......: ReplyEvent
// Purpose....: Callback function for reply event notification
//
// Parameters.: hSession - HPOWERTCP Session id.
// UserData - DWORD User data supplied to loginhost.
// Status - FTP_STATUS, status of ftp dialog (enumerated type)
// LastCommand - FTP_COMMAND last ftp command (enumerated type)
// ReplyCode - int ftp protocol return code
// ReplyStr - LPCSTR reply string
//
// Returns....: void
//---------------------------------------------------------------------------
void CALLBACK ReplyEvent(HPOWERTCP hSession,
DWORD UserData,
FTP_STATUS Status,
FTP_COMMAND LastCommand,
int ReplyCode,
LPCSTR ReplyStr)
{ LPSTR s;
LPSTR token;
// ReplyEvent notifications may have embedded <cr><lf>'s. Since
// we are dropping the text in an list box, we need to break
// the string into multiple pieces. The strtok function does
// just what we need. First we duplicate the string, since
// strtok modifies the passed in string, and ReplyStr doesn't
// really 'belong' to us.
s = _fstrdup(ReplyStr);
if(s)
{
token = _fstrtok(s,(LPSTR)"\r\n");
while(token)
{
SendDlgItemMessage((HWND)(WORD)UserData,LBC_REPLIES,LB_ADDSTRING
,0,(LPARAM)token);
token = _fstrtok(NULL,"\r\n");
}
_ffree(s);
}
else
{
// In the unlikely event that _fstrdup failed, drop the
// entire string into the list box.
SendDlgItemMessage((HWND)(WORD)UserData,LBC_REPLIES,LB_ADDSTRING
,0,(LPARAM)ReplyStr);
}
// If connection is closed, then hFtp is no longer valid.
if(LastCommand == FTP_CLOSED)
{
AbortSend(); // Cleanup just in case.
AbortRecv();
hFtp = NULL;
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,"Closed");
// Close app when connection closed? (See WM_SYSCOMMAND).
if(ClosePending)
{
ClosePending = FALSE;
PostQuitMessage(0);
}
}
}
//---------------------------------------------------------------------------
// Name.......: SendEvent
// Purpose....: Callback function for send event notification
//
// Parameters.: hSession - HPOWERTCP Session id.
// UserData - DWORD User data supplied to loginhost.
// Tag - DWORD Tag, Not used by FTP
//
// Returns....: void
//---------------------------------------------------------------------------
void CALLBACK SendEvent(HPOWERTCP hSession,DWORD UserData,DWORD Tag)
{ UINT Bytes;
char Status[40];
// This callback is invoked when data we have sent has been
// accepted by the transport layer. We can now send the
// next chunk.
if(hSendFile != HFILE_ERROR)
{
// Read next chunk from file.
Bytes = _lread(hSendFile,SendBuffer,SEND_BUFFER_SIZE);
if((HFILE)Bytes == HFILE_ERROR)
{ // Error reading file, close file and data connection,
// post error message in status line.
AbortSend();
CloseDataFtp(hSession);
wsprintf(Status,"%ld bytes sent. Error Reading File.",BytesSent);
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,Status);
return; // No more data to send, return.
}
// If we have reached end of file, close the file and
// the data connection. Indicate DONE in status line.
if(Bytes == 0)
{
_lclose(hSendFile);
hSendFile = HFILE_ERROR;
CloseDataFtp(hSession);
wsprintf(Status,"%ld bytes sent. DONE.",BytesSent);
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,Status);
return; // No more data to send, return.
}
// Send this block, update statistics and status line.
SendFtp(hSession,SendBuffer,Bytes);
BytesSent += Bytes;
wsprintf(Status,"%ld bytes sent.",BytesSent);
SetDlgItemText((HWND)(WORD)UserData,STC_STATUS,Status);
}
}
/****************************************************************************
* ActionXxx Functions. Handle user actions, dispatched from MainWndProc.
*
* All functions follow the same general format:
* 1) Get parameters from edit controls.
* 2) Call xxxFtp(parameters).
* 3) Display results of call.
* 4) _ffree any strings allocated for parameters.
*
****************************************************************************/
//---------------------------------------------------------------------------
// Name.......: ActionAbort
// Purpose....: Handle BTN_ABORT command.
//---------------------------------------------------------------------------
static void ActionAbort(HWND hWnd)
{ BOOL res;
// Closedown files we may be sending/receiving
AbortSend();
AbortRecv();
res = AbortFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionAllocate
// Purpose....: Handle BTN_ALLOCATE command.
//---------------------------------------------------------------------------
static void ActionAllocate(HWND hWnd)
{ LONG MaxFileSize;
LONG MaxRecordSize;
BOOL res;
if( GetLongParam(hWnd,EDC_PARAM1,(LPDWORD)&MaxFileSize)
&&
GetLongParam(hWnd,EDC_PARAM2,(LPDWORD)&MaxRecordSize))
{
res = AllocateFtp(hFtp,MaxFileSize,MaxRecordSize);
ShowResult(hWnd,res);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionAppe
// Purpose....: Handle BTN_APPE command.
//---------------------------------------------------------------------------
static void ActionAppe(HWND hWnd)
{ char *PathName;
char *LocalName;
BOOL res;
LocalName = GetStringParam(hWnd,EDC_PARAM2,TRUE);
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName && LocalName)
{
if(StartSend(hWnd,LocalName))
{
res = AppeFtp(hFtp,PathName);
if(!res)
{
AbortSend();
}
ShowResult(hWnd,res);
}
}
FreeStringParam(PathName);
FreeStringParam(LocalName);
}
//---------------------------------------------------------------------------
// Name.......: ActionChDir
// Purpose....: Handle BTN_CHDIR command.
//---------------------------------------------------------------------------
static void ActionChDir(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName)
{
res = ChDirFtp(hFtp,PathName);
ShowResult(hWnd,res);
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionChDirUp
// Purpose....: Handle BTN_CHDIRUP command.
//---------------------------------------------------------------------------
static void ActionChDirUp(HWND hWnd)
{ BOOL res;
res = ChDirUpFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionClose
// Purpose....: Handle BTN_CLOSE command.
//---------------------------------------------------------------------------
static void ActionClose(HWND hWnd)
{ BOOL res;
// Closedown files we may be sending/receiving
AbortSend();
AbortRecv();
res = CloseFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionCloseData
// Purpose....: Handle BTN_CLOSEDATA command.
//---------------------------------------------------------------------------
static void ActionCloseData(HWND hWnd)
{ BOOL res;
// Closedown files we may be sending/receiving
AbortSend();
AbortRecv();
res = CloseDataFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionCommand
// Purpose....: Handle BTN_COMMAND command.
//---------------------------------------------------------------------------
static void ActionCommand(HWND hWnd)
{ char *CommandStr;
BOOL res;
CommandStr = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(CommandStr)
{
res = CommandFtp(hFtp,CommandStr);
ShowResult(hWnd,res);
FreeStringParam(CommandStr);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionDelete
// Purpose....: Handle BTN_DELETE command.
//---------------------------------------------------------------------------
static void ActionDelete(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName)
{
res = DeleteFtp(hFtp,PathName);
ShowResult(hWnd,res);
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionFileStruct
// Purpose....: Handle BTN_FILESTRUCT command.
//---------------------------------------------------------------------------
static void ActionFileStruct(HWND hWnd)
{ BOOL res;
char *StructName;
FTP_FILE_STRUCT Structure;
StructName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(StructName)
{
if( stricmp(StructName,"FTP_FILE")==0 ||
stricmp(StructName,"FILE")==0)
{
Structure = FTP_FILE;
}
else if( stricmp(StructName,"FTP_RECORD") == 0 ||
stricmp(StructName,"RECORD") == 0)
{
Structure = FTP_RECORD;
}
else if( stricmp(StructName,"FTP_PAGE") == 0 ||
stricmp(StructName,"PAGE") == 0)
{
Structure = FTP_PAGE;
}
else
{
FreeStringParam(StructName);
SetDlgItemText(hWnd,STC_STATUS,"Enter: file,record or page");
return;
}
res = FileStructFtp(hFtp,Structure);
ShowResult(hWnd,res);
FreeStringParam(StructName);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionHelp
// Purpose....: Handle BTN_HELP command.
//---------------------------------------------------------------------------
static void ActionHelp(HWND hWnd)
{ char *Command;
BOOL res;
Command = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(Command)
{
res = HelpFtp(hFtp,Command);
ShowResult(hWnd,res);
FreeStringParam(Command);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionLastCommand
// Purpose....: Handle BTN_LASTCOMMAND command.
//---------------------------------------------------------------------------
static void ActionLastCommand(HWND hWnd)
{ BOOL res;
res = LastCommandFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionList
// Purpose....: Handle BTN_LIST command.
//---------------------------------------------------------------------------
static void ActionList(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,FALSE);
if(PathName)
{
if(StartReceive(hWnd,NULL))
{
res = ListFtp(hFtp,PathName);
if(!res)
{
AbortRecv();
}
ShowResult(hWnd,res);
}
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionLoginHost
// Purpose....: Handle BTN_LOGINHOST command.
//---------------------------------------------------------------------------
static void ActionLoginHost(HWND hWnd)
{ char *HostName;
char *UserName;
char *Password;
char *Account;
char *License;
char Status[32];
UserName = GetStringParam(hWnd,EDC_USER,TRUE);
HostName = GetStringParam(hWnd,EDC_HOST,TRUE);
Password = GetStringParam(hWnd,EDC_PASSWORD,FALSE);
Account = GetStringParam(hWnd,EDC_ACCOUNT,FALSE);
License = GetStringParam(hWnd,EDC_LICENSE,FALSE);
if(HostName && UserName)
{
hFtp = LoginHostFtp((DWORD)MAKELONG(hWnd,0),
License,
PT_DEBUG,
HostName,
NULL,
UserName,
Password,
Account,
lpfnConnectEvent,
lpfnLogEvent,
lpfnRecvEvent,
lpfnReplyEvent,
lpfnSendEvent);
if(hFtp)
{
wsprintf(Status,"Login OK. Handle=%x",hFtp);
SetDlgItemText(hWnd,STC_STATUS,Status);
}
else
{
ShowResult(hWnd,FALSE);
}
}
FreeStringParam(HostName);
FreeStringParam(UserName);
FreeStringParam(Password);
FreeStringParam(Account);
FreeStringParam(License);
}
//---------------------------------------------------------------------------
// Name.......: ActionLogout
// Purpose....: Handle BTN_LOGOUT command.
//---------------------------------------------------------------------------
static void ActionLogout(HWND hWnd)
{ BOOL res;
res = LogoutFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionMakeDir
// Purpose....: Handle BTN_MAKEDIR command.
//---------------------------------------------------------------------------
static void ActionMakeDir(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName)
{
res = MakeDirFtp(hFtp,PathName);
ShowResult(hWnd,res);
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionMode
// Purpose....: Handle BTN_MODE command.
//---------------------------------------------------------------------------
static void ActionMode(HWND hWnd)
{ BOOL res;
FTP_TRANSFER_MODE Mode;
char *ModeName;
ModeName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(ModeName)
{
if( stricmp(ModeName,"FTP_STREAM")==0 ||
stricmp(ModeName,"STREAM")==0)
{
Mode = FTP_STREAM;
}
else if( stricmp(ModeName,"FTP_BLOCK") == 0 ||
stricmp(ModeName,"BLOCK") == 0)
{
Mode = FTP_BLOCK;
}
else if( stricmp(ModeName,"FTP_COMPRESSED") == 0 ||
stricmp(ModeName,"COMPRESSED") == 0)
{
Mode = FTP_COMPRESSED;
}
else
{
SetDlgItemText(hWnd,STC_STATUS,"Enter: stream,block or compressed");
FreeStringParam(ModeName);
return;
}
res = ModeFtp(hFtp,Mode);
ShowResult(hWnd,res);
FreeStringParam(ModeName);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionNameList
// Purpose....: Handle BTN_NAMELIST command.
//---------------------------------------------------------------------------
static void ActionNameList(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,FALSE);
if(PathName)
{
if(StartReceive(hWnd,NULL))
{
res = NameListFtp(hFtp,PathName);
if(!res)
{
AbortRecv();
}
ShowResult(hWnd,res);
}
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......: ActionNoop
// Purpose....: Handle BTN_NOOP command.
//---------------------------------------------------------------------------
static void ActionNoop(HWND hWnd)
{ BOOL res;
res = NoopFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionPassive
// Purpose....: Handle BTN_PASSIVE command.
//---------------------------------------------------------------------------
static void ActionPassive(HWND hWnd)
{ BOOL res;
res = PassiveFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......: ActionPort
// Purpose....: Handle BTN_PORT command.
//---------------------------------------------------------------------------
static void ActionPort(HWND hWnd)
{ char *HostPort;
BOOL res;
HostPort = GetStringParam(hWnd,EDC_PARAM1,FALSE);
if(HostPort)
{
res = PortFtp(hFtp,HostPort);
ShowResult(hWnd,res);
FreeStringParam(HostPort);
}
}
//---------------------------------------------------------------------------
// Name.......:ActionPrintWorkingDir
// Purpose....:Handle BTN_PRINTWORKINGDIR command.
//---------------------------------------------------------------------------
static void ActionPrintWorkingDir(HWND hWnd)
{ BOOL res;
res = PrintWorkingDirFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......:ActionReinitialize
// Purpose....:Handle BTN_REINITIALIZE command.
//---------------------------------------------------------------------------
static void ActionReinitialize(HWND hWnd)
{ BOOL res;
res = ReinitializeFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......:ActionRemoveDir
// Purpose....:Handle BTN_REMOVEDIR command.
//---------------------------------------------------------------------------
static void ActionRemoveDir(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName)
{
res = RemoveDirFtp(hFtp,PathName);
ShowResult(hWnd,res);
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......:ActionRename
// Purpose....:Handle BTN_RENAME command.
//---------------------------------------------------------------------------
static void ActionRename(HWND hWnd)
{ char *FromPathName;
char *ToPathName;
BOOL res;
ToPathName = GetStringParam(hWnd,EDC_PARAM2,TRUE);
FromPathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(FromPathName && ToPathName)
{
res = RenameFtp(hFtp,FromPathName,ToPathName);
ShowResult(hWnd,res);
}
FreeStringParam(FromPathName);
FreeStringParam(ToPathName);
}
//---------------------------------------------------------------------------
// Name.......:ActionRestart
// Purpose....:Handle BTN_RESTART command.
//---------------------------------------------------------------------------
static void ActionRestart(HWND hWnd)
{ char *Marker;
BOOL res;
Marker = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(Marker)
{
res = RestartFtp(hFtp,Marker);
ShowResult(hWnd,res);
FreeStringParam(Marker);
}
}
//---------------------------------------------------------------------------
// Name.......:ActionRetrieve
// Purpose....:Handle BTN_RETRIEVE command.
//---------------------------------------------------------------------------
static void ActionRetrieve(HWND hWnd)
{ char *PathName;
char *LocalName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
LocalName = GetStringParam(hWnd,EDC_PARAM2,FALSE);
if(PathName)
{
if(StartReceive(hWnd,*LocalName ? LocalName : NULL))
{
res = RetrieveFtp(hFtp,PathName);
if(!res)
{
AbortRecv();
}
ShowResult(hWnd,res);
}
FreeStringParam(PathName);
}
FreeStringParam(LocalName);
}
//---------------------------------------------------------------------------
// Name.......:ActionSite
// Purpose....:Handle BTN_SITE command.
//---------------------------------------------------------------------------
static void ActionSite(HWND hWnd)
{ char *Desc;
BOOL res;
Desc = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(Desc)
{
res = SiteFtp(hFtp,Desc);
ShowResult(hWnd,res);
FreeStringParam(Desc);
}
}
//---------------------------------------------------------------------------
// Name.......:ActionStatus
// Purpose....:Handle BTN_STATUS command.
//---------------------------------------------------------------------------
static void ActionStatus(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName)
{
res = StatusFtp(hFtp,PathName);
ShowResult(hWnd,res);
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......:ActionStore
// Purpose....:Handle BTN_STORE command.
//---------------------------------------------------------------------------
static void ActionStore(HWND hWnd)
{ char *PathName;
char *LocalName;
BOOL res;
LocalName = GetStringParam(hWnd,EDC_PARAM2,TRUE);
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName && LocalName)
{
if(StartSend(hWnd,LocalName))
{
res = StoreFtp(hFtp,PathName);
if(!res)
{
AbortSend();
}
ShowResult(hWnd,res);
}
}
FreeStringParam(PathName);
FreeStringParam(LocalName);
}
//---------------------------------------------------------------------------
// Name.......:ActionStoreUnique
// Purpose....:Handle BTN_STOREUNIQUE command.
//---------------------------------------------------------------------------
static void ActionStoreUnique(HWND hWnd)
{ char *PathName;
char *LocalName;
BOOL res;
LocalName = GetStringParam(hWnd,EDC_PARAM2,TRUE);
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName && LocalName)
{
if(StartSend(hWnd,LocalName))
{
res = StoreUniqueFtp(hFtp,PathName);
if(!res)
{
AbortSend();
}
ShowResult(hWnd,res);
}
}
FreeStringParam(PathName);
FreeStringParam(LocalName);
}
//---------------------------------------------------------------------------
// Name.......:ActionStructMount
// Purpose....:Handle BTN_STRUCTMOUNT command.
//---------------------------------------------------------------------------
static void ActionStructMount(HWND hWnd)
{ char *PathName;
BOOL res;
PathName = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(PathName)
{
res = StructMountFtp(hFtp,PathName);
ShowResult(hWnd,res);
FreeStringParam(PathName);
}
}
//---------------------------------------------------------------------------
// Name.......:ActionSystem
// Purpose....:Handle BTN_SYSTEM command.
//---------------------------------------------------------------------------
static void ActionSystem(HWND hWnd)
{ BOOL res;
res = SystemFtp(hFtp);
ShowResult(hWnd,res);
}
//---------------------------------------------------------------------------
// Name.......:ActionType
// Purpose....:Handle BTN_TYPE command.
//---------------------------------------------------------------------------
static void ActionType(HWND hWnd)
{ char *RepType;
BOOL res;
RepType = GetStringParam(hWnd,EDC_PARAM1,TRUE);
if(RepType)
{
res = TypeFtp(hFtp,RepType);
ShowResult(hWnd,res);
FreeStringParam(RepType);
}
}
//---------------------------------------------------------------------------
// Name.......:ActionClearLog
// Purpose....:Handle BTN_CLEARLOG command.
//---------------------------------------------------------------------------
static void ActionClearLog(HWND hWnd)
{
SendDlgItemMessage(hWnd,LBC_LOG,LB_RESETCONTENT,0,0);
}
//---------------------------------------------------------------------------
// Name.......:ActionClearReplies
// Purpose....:Handle BTN_CLEARREPLIES command.
//---------------------------------------------------------------------------
static void ActionClearReplies(HWND hWnd)
{
SendDlgItemMessage(hWnd,LBC_REPLIES,LB_RESETCONTENT,0,0);
}
//---------------------------------------------------------------------------
// Name.......:ShowParams
// Purpose....:Show parameters for given button.
//---------------------------------------------------------------------------
static void ShowParams(HWND hOurWnd,HWND hCtlWnd)
{ int id;
char *p1;
char *p2;
id = GetDlgCtrlID(hCtlWnd);
switch(id)
{
// No param
case BTN_CHDIRUP:
case BTN_CLOSEDATA:
case BTN_LASTCOMMAND:
case BTN_NOOP:
case BTN_PASSIVE:
case BTN_PRINTWORKINGDIR:
case BTN_SYSTEM:
p1=p2="";
break;
case BTN_APPE:
case BTN_STORE:
case BTN_STOREUNIQUE:
case BTN_RETRIEVE:
p1="PathName";
p2="LocalName";
break;
// pathname
case BTN_CHDIR:
case BTN_DELETE:
case BTN_LIST:
case BTN_MAKEDIR:
case BTN_NAMELIST:
case BTN_REMOVEDIR:
case BTN_STATUS:
case BTN_STRUCTMOUNT:
p1="PathName";
p2="";
break;
// command
case BTN_COMMAND:
case BTN_HELP:
p1="Command";
p2="";
break;
case BTN_ALLOCATE:
p1="FileSize";
p2="RecordSize";
break;
case BTN_FILESTRUCT:
p1="Structure";
p2="";
break;
case BTN_MODE:
p1="XferMode";
p2="";
break;
case BTN_PORT:
p1="HostPort";
p2="";
break;
case BTN_RENAME:
p1="FromName";
p2="ToName";
break;
case BTN_RESTART:
p1="Marker";
p2="";
break;
case BTN_SITE:
p1="Desc";
p2="";
break;
case BTN_TYPE:
p1="RepType";
p2="";
break;
default: return;
}
SetDlgItemText(hOurWnd,STC_PARAM1,p1);
SetDlgItemText(hOurWnd,STC_PARAM2,p2);
}
//---------------------------------------------------------------------------
// Name.......:CanClose
// Purpose....:Return TRUE if ok to close
//---------------------------------------------------------------------------
static BOOL CanClose(HWND hWnd)
{ int res;
// User wants to shut down. If still logged on (hFtp != NULL)
// encourge user to log off first.
if(!hFtp)
{
return TRUE;
}
res = MessageBox(hWnd,
"You are still logged on.\n"
"You should logout before closing.\n"
"Would you like to logout now?",
"FTPTest",
MB_YESNOCANCEL | MB_ICONQUESTION);
switch(res)
{
case IDYES: ClosePending = TRUE;
LogoutFtp(hFtp);
return FALSE;
case IDNO: return TRUE;
case IDCANCEL: return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
// Name.......:ReadIniFile
// Purpose....:Reads default login values.
//---------------------------------------------------------------------------
static void ReadIniFile(HWND hWnd)
{ char *Name;
Name = malloc(256);
if(!Name)
{
return;
}
GetPrivateProfileString("FTPTest",
"RemoteHost",
"",
Name,
256,
"FTPTEST.INI");
SendDlgItemMessage(hWnd,EDC_HOST,WM_SETTEXT,0,(LPARAM)(LPCSTR)Name);
GetPrivateProfileString("FTPTest",
"User",
"",
Name,
256,
"FTPTEST.INI");
SendDlgItemMessage(hWnd,EDC_USER,WM_SETTEXT,0,(LPARAM)(LPCSTR)Name);
GetPrivateProfileString("FTPTest",
"LicenseKey",
"",
Name,
256,
"FTPTEST.INI");
SendDlgItemMessage(hWnd,EDC_LICENSE,WM_SETTEXT,0,(LPARAM)(LPCSTR)Name);
GetPrivateProfileString("FTPTest",
"Account",
"",
Name,
256,
"FTPTEST.INI");
SendDlgItemMessage(hWnd,EDC_ACCOUNT,WM_SETTEXT,0,(LPARAM)(LPCSTR)Name);
free(Name);
}
//---------------------------------------------------------------------------
// Name.......:WriteIniFile
// Purpose....:Writes current login values.
//---------------------------------------------------------------------------
static void WriteIniFile(HWND hWnd)
{ char *Name;
Name = GetStringParam(hWnd,EDC_HOST,FALSE);
if(Name)
{
WritePrivateProfileString("FTPTest",
"RemoteHost",
Name,
"FTPTEST.INI");
FreeStringParam(Name);
}
Name = GetStringParam(hWnd,EDC_USER,FALSE);
if(Name)
{
WritePrivateProfileString("FTPTest",
"User",
Name,
"FTPTEST.INI");
FreeStringParam(Name);
}
Name = GetStringParam(hWnd,EDC_LICENSE,FALSE);
if(Name)
{
WritePrivateProfileString("FTPTest",
"LicenseKey",
Name,
"FTPTEST.INI");
FreeStringParam(Name);
}
Name = GetStringParam(hWnd,EDC_ACCOUNT,FALSE);
if(Name)
{
WritePrivateProfileString("FTPTest",
"Account",
Name,
"FTPTEST.INI");
FreeStringParam(Name);
}
}
//---------------------------------------------------------------------------
// Name.......:MainWndProc
// Purpose....:Main windows procedure for FTPTest.
//---------------------------------------------------------------------------
static DLGPROC lpfnMainWndProc;
BOOL CALLBACK MainWndProc(HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
static HWND hCursorWnd;
HDC hDc;
PAINTSTRUCT ps;
switch(wMessage)
{
case WM_INITDIALOG :
// Get default login values, init status line, put
// cursor in HostName edit control
ReadIniFile(hWnd);
SetDlgItemText(hWnd,STC_STATUS,"FTPTest Version 1.0");
SetFocus(GetDlgItem(hWnd,EDC_HOST));
SendDlgItemMessage(hWnd,LBC_LOG , LB_SETHORIZONTALEXTENT,
800, 0L);
SendDlgItemMessage(hWnd,LBC_REPLIES , LB_SETHORIZONTALEXTENT,
800, 0L);
return TRUE;
case WM_COMMAND :
// Dispatch a button click.
switch(wParam)
{
case BTN_ABORT: ActionAbort(hWnd); break;
case BTN_ALLOCATE: ActionAllocate(hWnd); break;
case BTN_APPE: ActionAppe(hWnd); break;
case BTN_CHDIR: ActionChDir(hWnd); break;
case BTN_CHDIRUP: ActionChDirUp(hWnd); break;
case BTN_CLOSE: ActionClose(hWnd); break;
case BTN_CLOSEDATA: ActionCloseData(hWnd); break;
case BTN_COMMAND: ActionCommand(hWnd); break;
case BTN_DELETE: ActionDelete(hWnd); break;
case BTN_FILESTRUCT: ActionFileStruct(hWnd); break;
case BTN_HELP: ActionHelp(hWnd); break;
case BTN_LASTCOMMAND: ActionLastCommand(hWnd); break;
case BTN_LIST: ActionList(hWnd); break;
case BTN_LOGINHOST: ActionLoginHost(hWnd); break;
case BTN_LOGOUT: ActionLogout(hWnd); break;
case BTN_MAKEDIR: ActionMakeDir(hWnd); break;
case BTN_MODE: ActionMode(hWnd); break;
case BTN_NAMELIST: ActionNameList(hWnd); break;
case BTN_NOOP: ActionNoop(hWnd); break;
case BTN_PASSIVE: ActionPassive(hWnd); break;
case BTN_PORT: ActionPort(hWnd); break;
case BTN_PRINTWORKINGDIR: ActionPrintWorkingDir(hWnd); break;
case BTN_REINITIALIZE: ActionReinitialize(hWnd); break;
case BTN_REMOVEDIR: ActionRemoveDir(hWnd); break;
case BTN_RENAME: ActionRename(hWnd); break;
case BTN_RESTART: ActionRestart(hWnd); break;
case BTN_RETRIEVE: ActionRetrieve(hWnd); break;
case BTN_SITE: ActionSite(hWnd); break;
case BTN_STATUS: ActionStatus(hWnd); break;
case BTN_STORE: ActionStore(hWnd); break;
case BTN_STOREUNIQUE: ActionStoreUnique(hWnd); break;
case BTN_STRUCTMOUNT: ActionStructMount(hWnd); break;
case BTN_SYSTEM: ActionSystem(hWnd); break;
case BTN_TYPE: ActionType(hWnd); break;
case BTN_CLEARLOG: ActionClearLog(hWnd); break;
case BTN_CLEARREPLIES: ActionClearReplies(hWnd); break;
}
break;
case WM_MOUSEACTIVATE:
// If button in Data group clicked with left or
// right button, show the parameters for that button.
ShowParams(hWnd,hCursorWnd);
if(HIWORD(lParam) == WM_RBUTTONDOWN)
{
return MA_NOACTIVATE;
}
else
{
return MA_ACTIVATE;
}
// break;
case WM_SETCURSOR:
// Keep track of which control the mouse is over.
hCursorWnd = (HWND)wParam;
break;
case WM_SYSCOMMAND :
switch(wParam & 0xFFF0)
{
case SC_CLOSE :
// Save login information, see if ok to quit.
WriteIniFile(hWnd);
if(CanClose(hWnd))
{
PostQuitMessage(0);
return TRUE;
}
else
{
return FALSE;
}
}
break;
case WM_PAINT:
// Since we don't register a class, we draw our own
// icon when we are minimized.
if(IsIconic(hWnd))
{
hDc = BeginPaint(hWnd,&ps);
DrawIcon(hDc,0,0,hOurIcon);
EndPaint(hWnd,&ps);
}
break;
case WM_ERASEBKGND:
// The icon contains some transparent pixels. If we
// just ignore the erase background message, then
// DefDlgProc paints the background white. If we
// swallow the message, then garbage is left in the
// transparent areas when another window hides the
// icon and is then moved. Microsoft solved this problem
// years ago. The solution is in DefWindowProc, case
// WM_ICONERASEBKGND. So let them do the work!
if(IsIconic(hWnd))
{
return (BOOL)DefWindowProc(hWnd,WM_ICONERASEBKGND,wParam,lParam);
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default :
return FALSE;
}
return FALSE;
}
//---------------------------------------------------------------------------
// Name.......:WinMain
// Purpose....:Create application dialog and dispatch messages.
//---------------------------------------------------------------------------
int PASCAL WinMain(HINSTANCE hInstance, // Application Instance Handle
HINSTANCE hPrevInstance, // Previous Instance Handle
LPSTR lpszCmdLine, // Pointer to Command Line
int nCmdShow) // Show Window Option
{
static char szAppName[] = "FTPtest";
HINSTANCE hInst;
MSG msg;
HWND hWndMain;
hInst = hInstance;
hOurIcon = LoadIcon(hInst,szAppName);
lpfnMainWndProc = (DLGPROC)MakeProcInstance((FARPROC)MainWndProc,hInst);
lpfnConnectEvent = (CONNECTEVENT)MakeProcInstance((FARPROC)ConnectEvent,
hInst);
lpfnLogEvent = (LOGEVENT)MakeProcInstance((FARPROC)LogEvent,hInst);
lpfnRecvEvent = (RECVEVENT)MakeProcInstance((FARPROC)RecvEvent,hInst);
lpfnReplyEvent = (REPLYEVENT)MakeProcInstance((FARPROC)ReplyEvent,hInst);
lpfnSendEvent = (SENDEVENT)MakeProcInstance((FARPROC)SendEvent,hInst);
if(!(hWndMain = CreateDialog(hInst,
szAppName,
NULL,
lpfnMainWndProc)))
{
MessageBox(NULL, "Unable to display main dialog", "System Error", MB_OK);
return FALSE;
}
ShowWindow(hWndMain, nCmdShow);
UpdateWindow(hWndMain);
while(GetMessage(&msg, NULL, 0, 0))
if(!IsDialogMessage(hWndMain, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
FreeProcInstance((FARPROC)lpfnMainWndProc);
FreeProcInstance((FARPROC)lpfnConnectEvent);
FreeProcInstance((FARPROC)lpfnLogEvent);
FreeProcInstance((FARPROC)lpfnRecvEvent);
FreeProcInstance((FARPROC)lpfnReplyEvent);
FreeProcInstance((FARPROC)lpfnSendEvent);
return msg.wParam;
}